package ygw.study.designPatterns.flyweight;

import org.junit.jupiter.api.Test;

/**
 * <p>
 * 设计模式-享元模式
 * </p>
 * <p>
 * Copyright:2021.All rights reserved.
 * </p>
 * <p>
 * Company:Zsoft
 * </p>
 * <p>
 * CreateDate:2021-05-19 20:10
 * </p>
 *
 * @author YuGongWen
 * @history Mender:YuGongWen；Date:2021-05-19 20:10；
 */
public class TestFlyweightPattern {
    private static final String colors[] =
            {"Red", "Green", "Blue", "White", "Black"};

 

    @Test
    public void test1(){
        for (int i = 0; i < 2*10000; ++i) {
            Circle circle =  (Circle) ShapeFactory.getCircle(getRandomColor());
            circle.setX(getRandomX());
            circle.setY(getRandomY());
            circle.setRadius(100);
            circle.draw();
        }
    }


    @Test
    public void test2(){
        for (int i = 0; i < 2*10000; ++i) {
            Circle circle =  new Circle(getRandomColor());
            circle.setX(getRandomX());
            circle.setY(getRandomY());
            circle.setRadius(100);
            circle.draw();
        }
    }
    
    
    
    
    private static String getRandomColor() {
        return colors[(int) (Math.random() * colors.length)];
    }

    private static int getRandomX() {
        return (int) (Math.random() * 100);
    }

    private static int getRandomY() {
        return (int) (Math.random() * 100);
    }
}